using System.Threading.Tasks;
using Admin.NET.Application.Entity.Business;
using Admin.NET.Application.Service.Special.Dto;
using Admin.NET.Core;
using Furion;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;

namespace Admin.NET.Application.Service.Special;

/// <summary>
/// 特殊指令配置
/// </summary>
[ApiDescriptionSettings(new string[] { "业务应用" }, Order = 100)]
public class SpecialInstructionsService : IDynamicApiController, ITransient, IPrivateDependency
{
	private readonly SqlSugarRepository<SpecialInstructions> _rep;

	public SpecialInstructionsService(SqlSugarRepository<SpecialInstructions> rep)
	{
		_rep = rep;
	}

	/// <summary>
	/// 保存配置
	/// </summary>
	/// <param name="input"></param>
	/// <returns></returns>
	[HttpPost("/specialinstructions/edit")]
	public async Task EditSpecialInstructions(SpecialInstructionsInput input)
	{
		SpecialInstructions entity = input.Adapt<SpecialInstructions>();
		await _rep.InsertOrUpdateAsync(entity);
	}

	/// <summary>
	/// 查询配置
	/// </summary>
	/// <returns></returns>
	[HttpGet("/specialinstructions/list/")]
	public async Task<SpecialInstructionsInput> GetWxPay()
	{
		SpecialInstructionsInput specialInstructionsInput = new SpecialInstructionsInput();
		long TenantId = long.Parse(App.User.FindFirst("TenantId").Value);
		SpecialInstructions model = await _rep.GetFirstAsync((SpecialInstructions u) => u.TenantId == (long?)TenantId);
		if (model != null)
		{
			specialInstructionsInput = model.Adapt<SpecialInstructionsInput>();
		}
		return specialInstructionsInput;
	}

	/// <summary>
	/// 删除配置
	/// </summary>
	/// <returns></returns>
	[HttpPost("/specialinstructions/delete")]
	public async Task Deletewx()
	{
		long TenantId = long.Parse(App.User.FindFirst("TenantId").Value);
		await _rep.DeleteAsync((SpecialInstructions u) => u.TenantId == (long?)TenantId);
	}
}
